
package com.ce.cases.source.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import com.ce.cases.source.view.CaseSourceView;
import com.ce.framework.datamaintain.action.SearchAction;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.util.OrgUtil;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-18
* 创建时间：15:29:27
* 功能描述：备选案源台账 [CASE_SOURCE]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseAllSourceSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{

	    private String taxpayerNum;
	    private String involvedEnt;
	    private String caseNum;
	    private String recBeginDate;
	    private String recEndDate;
	    private String caseFrom;
	    private String illegalType;
	    private String inspectDept;
	    private String collectDept;
	    private String curOrgId;
	    private String curPersonId;
	    private String curOrgLevel;
	    private String curOrgType;    
	   
		@Override
		public void initCondition(SearchAction action, boolean search)
				throws AppException {
			
			SysVOrg curOrg=OrgUtil.getOrg(User.getUserOrgId());
			this.curOrgId=curOrg.getVcId();
			this.curOrgLevel=curOrg.getVcOrgLevel();
			this.curPersonId=User.getUserId();
			this.curOrgType=curOrg.getVcType();
		}

		public String getSearchSql() throws AppException {
			
			StringBuffer sql = new StringBuffer("select t.*,work.VC_STATUS,work.VC_HANDLE_ORGNAME from CASE_SOURCE t,T_WORKFLOW_WORK work where t.vc_id=VC_RECORD_ID and t.VC_DEL$FLAG = 0 and work.VC_STATUS>=1 ");
			if("1".equals(this.curOrgLevel)){
				
			}else{
				if("2".equals(this.curOrgType)){
					sql.append(" and ('"+this.curOrgId+"' in work.VC_HANDLE_ORGIDS or work.VC_HANDLE_ORGID='"+this.curOrgId+"')");
				}
			}
			
			//采用变量绑定的方式提高查询效率
			if(StringUtil.isNotBlank(taxpayerNum)){
				sql.append(" and t.taxpayer_number like ${taxpayerNum}||'%'");
			}
			if(StringUtil.isNotBlank(involvedEnt)){
				sql.append(" and t.involved_enterprice like '%'||${involvedEnt}||'%'");
			}
			if(StringUtil.isNotBlank(caseNum)){
				sql.append(" and t.case_number=${caseNum}");
			}
			sql.append(this.getDateCondition("receive_date", recBeginDate, recEndDate));
			if(StringUtil.isNotBlank(caseFrom)){
				sql.append(" and t.case_from_num=${caseFrom}");
			}
			if(StringUtil.isNotBlank(illegalType)){
				sql.append(" and t.illegal_type_num=${illegalType}");
			}
			if(StringUtil.isNotBlank(inspectDept)){
				sql.append(" and t.inspection_dept_id=${inspectDept}");
			}
			if(StringUtil.isNotBlank(collectDept)){
				sql.append(" and t.collection_dept_id=${collectDept}");
			}
			
		
			/*=========自行修改该处代码================
			//实现排序的代码
			sql.append(" "+super.getOrderBy());
			======================================*/
			return sql.toString();
		}
		
		public Object fromSQLQuery(ResultSet rs, int num) {
			CaseSourceView view = new CaseSourceView();
			try {
				view.setVcId(rs.getString("VC_ID"));
				view.setCaseNumber(rs.getString("CASE_NUMBER"));
				view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
				view.setRegisterDeptId(rs.getString("REGISTER_DEPT_ID"));
				view.setRegisterDept(rs.getString("REGISTER_DEPT"));
				view.setRegisterDate(rs.getDate("REGISTER_DATE"));
				view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
				view.setInvolvedEnterprice(rs.getString("INVOLVED_ENTERPRICE"));
				view.setInspectionDeptId(rs.getString("INSPECTION_DEPT_ID"));
				view.setInspectionDept(rs.getString("INSPECTION_DEPT"));
				view.setCollectionDeptId(rs.getString("COLLECTION_DEPT_ID"));
				view.setCollectionDept(rs.getString("COLLECTION_DEPT"));
				view.setIsImportant(rs.getInt("IS_IMPORTANT"));
				view.setIsSecret(rs.getInt("IS_SECRET"));
				view.setCaseFromNum(rs.getString("CASE_FROM_NUM"));
				view.setCaseFromName(rs.getString("CASE_FROM_NAME"));
				view.setIllegalTypeNum(rs.getString("ILLEGAL_TYPE_NUM"));
				view.setIllegalTypeName(rs.getString("ILLEGAL_TYPE_NAME"));
				view.setReceiveDate(rs.getDate("RECEIVE_DATE"));
				view.setState(rs.getInt("VC_STATUS"));
				view.setReportId(rs.getString("REPORT_ID"));
				view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));			
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
			return view;
		}
		
		public ISQLMapper getSQLMapper() {
			
			return this;
		}

		public String getTaxpayerNum() {
			return taxpayerNum;
		}

		public void setTaxpayerNum(String taxpayerNum) {
			this.taxpayerNum = taxpayerNum;
		}

		

		public String getInvolvedEnt() {
			return involvedEnt;
		}

		public void setInvolvedEnt(String involvedEnt) {
			this.involvedEnt = involvedEnt;
		}

		public String getCaseNum() {
			return caseNum;
		}

		public void setCaseNum(String caseNum) {
			this.caseNum = caseNum;
		}

		public String getRecBeginDate() {
			return recBeginDate;
		}

		public void setRecBeginDate(String recBeginDate) {
			this.recBeginDate = recBeginDate;
		}

		public String getRecEndDate() {
			return recEndDate;
		}

		public void setRecEndDate(String recEndDate) {
			this.recEndDate = recEndDate;
		}

		public String getCaseFrom() {
			return caseFrom;
		}

		public void setCaseFrom(String caseFrom) {
			this.caseFrom = caseFrom;
		}

		public String getIllegalType() {
			return illegalType;
		}

		public void setIllegalType(String illegalType) {
			this.illegalType = illegalType;
		}

		public String getInspectDept() {
			return inspectDept;
		}

		public void setInspectDept(String inspectDept) {
			this.inspectDept = inspectDept;
		}

		public String getCollectDept() {
			return collectDept;
		}

		public void setCollectDept(String collectDept) {
			this.collectDept = collectDept;
		}

		public String getCurOrgId() {
			curOrgId=User.getUserOrgId();
			return curOrgId;
		}

		public void setCurOrgId(String curOrgId) {
			this.curOrgId = curOrgId;
		}

		public String getCurPersonId() {
			
			return curPersonId;
		}

		public void setCurPersonId(String curPersonId) {
			this.curPersonId = curPersonId;
		}

		public String getCurOrgLevel() {
			
			return curOrgLevel;
		}

		public void setCurOrgLevel(String curOrgLevel) {
			this.curOrgLevel = curOrgLevel;
		}
	
	

}

